local CanPoolObj = require("manager.CanPoolObj")
local OtherPlayer = class("OtherPlayer", CanPoolObj)
local InputConst = require("const.InputConst")
local Vector3 = require("utils.Vector3")
local UIUtils = require("utils.UIUtil")
local MathUtils = require("utils.MathUtils")
local GameUtils = require("utils.GameUtils")
local GameConst = require("const.GameConst")

function OtherPlayer:ctor(parent)
    local resource = {
        path = "Prefabs/Models/Characters",
        name = "OtherPlayer",
        parent = parent
    }
    OtherPlayer.super.ctor(self, resource)
end

function OtherPlayer:awake()
    self.forward = Vector3.new(0, 0, 0)
    self.lerp = 0
    self.animator = self.gameObject:GetComponent(typeof(CS.UnityEngine.Animator))
    self.controller = self.gameObject:GetComponent(typeof(CS.UnityEngine.CharacterController))
    self.moveDirection = Vector3.new(0, 0, 0)
    self._lastMove = false
end

function OtherPlayer:start()
    self.transform.position = self._initPos
end

function OtherPlayer:setName(name)
    self._textName.text = name
end

function OtherPlayer:setVelocity(velocity)
    self.moveDirection = velocity
    if self.moveDirection.x ~= 0 or self.moveDirection.z ~= 0 then
        self.animator:SetBool("isMoving", true)
    else
        self.animator:SetBool("isMoving", false)
    end
end

function OtherPlayer:setForward(forward)
    self.transform.forward = forward
end

function OtherPlayer:setPosition(pos)
    self._initPos = pos
end

function OtherPlayer:updateDt(dt)
    if not self.enabled then
        return
    end
    if self._initPos then
        self.transform.position = self._initPos
        self._initPos = nil
    else
        self:move(dt)
    end
end

function OtherPlayer:onTriggerEnter(other)
end

function OtherPlayer:move(dt)
    self.moveDirection.y = math.max(self.moveDirection.y - GameConst.GRAVITY * dt, -100)
    self.controller:Move(self.moveDirection * dt)
end

function OtherPlayer:onDestroy()
end

return OtherPlayer
